home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / MACAPP / PRE_3 / UPROGRES / SETLINEW.P next >
Text File  |  1990-08-20  |  2KB  |  92 lines

  1. {
  2.     A Hairline drawing control object, for thin lines printed on a LaserWriter.
  3.     It is an interface for the PicComment SetLineWidth.
  4.     
  5.     SetLineWidth v1.0 5-15-90 by Brian Arnold
  6.     Copyright (c) 1990 Carnegie Mellon University
  7.     All Rights Reserved.
  8.     
  9.     Like there's anything worth copyrighting here.
  10.     
  11.     To use this TLineDrawer, simply instantiate, call ILineDrawer and store the
  12.     object reference somewhere (in a global or field of an object, perhaps).
  13.     Call BeginThinLine( kLaserPixels ) when you want a hairline, EndThinLine when
  14.     through drawing, and call Free when deleting.
  15.     
  16.     NEEDS: FailNIL and DisposIfHandle from MacApp.  Add our own failure if you
  17.     don't have MacApp.
  18. }
  19.  
  20. CONST
  21.  
  22.     kSetLineWidth        = 182;            { PicComment for fractional width line drawing }
  23.     kLaserPixels        = 4;            { roughly 4 laserwriter pixels per monitor pixel }
  24.  
  25. TYPE
  26.         { data type for fractional width line drawing:
  27.             v/h of WidthPt describes fraction of QuickDraw pen size to use for drawing.
  28.         }
  29.         
  30.     WidthPt        = Point;
  31.     WidthPtr    = ^WidthPt;
  32.     WidthHandle    = ^WidthPtr;
  33.  
  34.     TLineDrawer = OBJECT( TObject )
  35.     
  36.         fWidth:                WidthHandle;        { handle to pen size ratio }
  37.         fDrawingThin:        BOOLEAN;            { whether we're currently drawing thin }
  38.  
  39.         PROCEDURE TLineDrawer.ILineDrawer;
  40.             { initialize fWidth, fDrawingThin }
  41.             
  42.         PROCEDURE TLineDrawer.BeginThinLine( pixels: INTEGER );
  43.             { prep thin line drawing, pass kLaserPixels }
  44.         
  45.         PROCEDURE TLineDrawer.EndThinLine;
  46.             { cleanup thin line drawing }
  47.             
  48.         PROCEDURE TLineDrawer.Free;
  49.             OVERRIDE;
  50.             { free up fWidth }
  51.  
  52.     END;
  53.  
  54. PROCEDURE TLineDrawer.ILineDrawer;
  55. BEGIN
  56.     fWidth := WidthHandle( NewHandle( SizeOf( WidthPt ) ) );
  57.     
  58. (* caller must handle failure *)
  59.     FailNIL( fWidth );
  60.  
  61.     fDrawingThin := FALSE;
  62. END;
  63.  
  64. PROCEDURE TLineDrawer.BeginThinLine( pixels: INTEGER );
  65. BEGIN
  66.     IF ( fDrawingThin = FALSE ) AND ( fWidth <> NIL ) THEN BEGIN
  67.     (* set h to pixels, v/h will be fraction of 1/72 *)
  68.         fWidth^^.h := pixels;
  69.         fWidth^^.v := 1;
  70.         PicComment( kSetLineWidth, SizeOf( widthPt ), Handle( fWidth ) );
  71.         fDrawingThin := TRUE;
  72.     END;
  73. END;
  74.  
  75. PROCEDURE TLineDrawer.EndThinLine;
  76. BEGIN
  77.     IF ( fDrawingThin = TRUE ) AND (fWidth <> NIL ) THEN BEGIN
  78.     (* flip h and v *)
  79.         fWidth^^.v := fWidth^^.h;
  80.         fWidth^^.h := 1;
  81.         PicComment( kSetLineWidth, SizeOf( widthPt ), Handle( fWidth ) );
  82.         fDrawingThin := FALSE;
  83.     END;
  84. END;    
  85.  
  86. PROCEDURE TLineDrawer.Free;
  87.     OVERRIDE;
  88. BEGIN
  89.     DisposIfHandle( Handle( fWidth ) );
  90.     
  91.     INHERITED Free;
  92. END;